<?php
require_once("./session.php");
require_once("../include/global.php");

$username = $_SESSION['username'];
$curtime = date("F j, Y, g:i A");

if(empty($_GET['action']))
{
    $sql = "select * from blog_category ";
	$result = mysql_query($sql) or die(mysql_error());
	if(mysql_num_rows($result) == 0) die("你还没有添加栏目.");
	
    print <<<HTML
<div id="blogpost" style="width:100%;margin:0 auto;">
  <div class="admin_title">发表日志</div>
  <div id="postcontent" >
  <form id="postArticle" action="./save.php?action=add" method="post">
  <input type="hidden" name="log_ID" value="0" />
  <input type="hidden" name="author" value="$username" />
  <input type="hidden" name="viewNums" value="0" />
  <input type="hidden" name="commNums" value="0" />
  <table width="100%" border="0" cellpadding="2" cellspacing="0">
            <tr>
              <td width="90" height="24" align="right">标题:</td>
              <td align="left">
			  <input name="title" type="text" class="inputBox" id="title" size="50" maxlength="100"/>			  </td>
            </tr>
            <tr>
              <td height="24" align="right">分类:</td>
              <td align="left">
HTML;
            ShowCategory(0);
			 
          print <<<HTML
                <label for="label2">
				<input name="IsCommentable" type="hidden" value="1" />
				<input name="IsCommentable" type="checkbox" id="label2" value="0" />
                禁止评论</label>
                <label for="label3">
				<input name="IsTop" type="hidden" value="0" />
				<input name="IsTop" type="checkbox" id="label3" value="1" />
                日志置顶</label>
                <label for="label4">
				<input name="IsShow" type="hidden" value="1" />
				<input name="IsShow" type="checkbox" id="label4" value="0" />
                隐藏日志</label>
				</td>
            </tr>
            <tr>
              <td height="24" align="right">来源:</td>
              <td width="668" align="left">
                <label for="from"><input name="from" type="text" id="from" value="本站原创" size="16" /></label>
                <label for="fromurl">ַ<input name="fromurl" type="text" id="fromurl" value="http://www.nonsenser.com" size="35" />
              </label>			  </td>
            </tr>
            <tr>
              <td height="24" align="right">发表时间:</td>
              <td align="left"><input name="posttime" type="text" id="posttime" size="35" value="$curtime" /></td>
            </tr>
            <tr>
              <td height="24" align="right">Tags:</td>
              <td align="left">
			  <input name="tags" type="text" value="" size="50" class="inputBox" />(Tag之间以逗号分隔)			  </td>
            </tr>
            <tr>
              <td height="24" align="right" valign="top">内容:</td>
              <td height="24" align="left" valign="top">
HTML;

            include("../editor/fckeditor.php");
            $oFCKeditor = new FCKeditor('FCKeditor') ;//
            $oFCKeditor->BasePath = '../editor/' ;//
            $oFCKeditor->ToolbarSet = 'Default' ;//
            $oFCKeditor->Create('EditorDefault', '40%',150) ;

print <<<HTML
              </td>
            </tr>
             
  
             <tr>
               <td  align="right" valign="top">摘要:</td>
               <td colspan="2" align="left" valign="top">
HTML;
            $oFCKeditor = new FCKeditor('Intro') ;//
            $oFCKeditor->BasePath = '../editor/' ;//
            $oFCKeditor->ToolbarSet = 'Default' ;//
            $oFCKeditor->Create() ;
print <<<HTML
			  </td>
             </tr>
          <tr>
              <td align="right" nowrap>附件:</td>
              <td colspan="2" align="left">
<iframe src="./postattach.php" scrolling="no" width="100%" height="24" frameborder="0"></iframe>              </td>
            </tr>
            <tr>
              <td colspan="3" align="center">
			  <input type="submit"value="提交日志"/>
              <input name="reset" type="button" value="取消" onClick="history.go(-1)"/>			  </td>
            </tr>
</table>
  </form>
  </div>
</div>
HTML;
}else{
     
	 if($_GET['action'] == "modify")
	 {
	     if(!empty($_GET['logID']) && is_numeric($_GET['logID']))
		 {
		     $sql = "select * from blog_article where log_ID = ".$_GET['logID']." limit 1";
			 $result = mysql_query($sql) or die(mysql_error());
			 $rs = mysql_fetch_object($result);
			 if(!$rs){ die("该文章不存在.");}
             
			 print <<<HTML
<div id="blogpost" style="width:100%;margin:0 auto;">
  <div class="admin_title">发表日志</div>
  <div id="postcontent" >
  <form id="postArticle" action="./save.php?action=modify" method="post">
  <input type="hidden" name="log_ID" value="$rs->log_ID" />
  <input type="hidden" name="author" value="$rs->log_Author" />
  <input type="hidden" name="viewNums" value="$rs->log_ViewNums" />
  <input type="hidden" name="commNums" value="$rs->log_CommNums" />
  <table width="100%" border="0" cellpadding="2" cellspacing="0">
            <tr>
              <td width="90" height="24" align="right">标题:</td>
              <td align="left" >
			  <input name="title" type="text" class="inputBox" id="title" size="50" maxlength="100" value="$rs->log_Title" /></td>
            </tr>
HTML;
?>
            <tr>
              <td height="24" align="right">分类:</td>
              <td align="left">
<?php
     ShowCategory($rs->log_CateID);
?>
                <label for="label2">
				<input name="IsCommentable" type="hidden" value="1" />
				<input name="IsCommentable" type="checkbox" id="label2" value="0" <?php echo $rs->log_IsCommentable?"":"CHECKED"; ?>/>
                禁止评论</label>
                <label for="label3">
				<input name="IsTop" type="hidden" value="0" />
				<input name="IsTop" type="checkbox" id="label3" value="1" <?php echo $rs->log_IsTop?"CHECKED":""; ?> />
                日志置顶</label>
				<label for="label4">
				<input name="IsShow" type="hidden" value="1" />
				<input name="IsShow" type="checkbox" id="label4" value="0" <?php echo $rs->log_IsShow?"":"CHECKED"; ?> />
                隐藏日志</label>
                </td>
            </tr>
<?php
       $time = strftime("%B %d,%Y,%H:%M %p",$rs->log_PostTime);
       print <<<HTML
            <tr>
              <td height="24" align="right">来源:</td>
              <td width="668" align="left">
                <label for="from"><input name="from" type="text" id="from" value="$rs->log_From" size="16" /></label>
                <label for="fromurl">ַ<input name="fromurl" type="text" id="fromurl" value="$rs->log_FromUrl" size="35" />
              </label>			  </td>
            </tr>
            <tr>
              <td height="24" align="right">发表时间:</td>
              <td align="left"><input name="posttime" type="text" id="posttime" size="35" value="$time" /></td>
            </tr>
            <tr>
              <td height="24" align="right">Tags:</td>
              <td align="left">
			  <input name="tags" type="text" value="" size="50" class="inputBox" value="$rs->log_Tags" />(Tag之间以逗号分隔)</td>
            </tr>
            <tr>
              <td height="24" align="right" valign="top">内容:</td>
              <td align="left" valign="top">
HTML;

            include("../editor/fckeditor.php");
            $oFCKeditor = new FCKeditor('FCKeditor') ;//
            $oFCKeditor->BasePath = '../editor/' ;//
            $oFCKeditor->ToolbarSet = 'Default' ;//
			$oFCKeditor->Value = $rs->log_Content;
            $oFCKeditor->Create() ;
			

print <<<HTML
              </td>
            </tr>
             
  
             <tr>
               <td  align="right" valign="top">摘要:</td>
               <td colspan="2" align="left" valign="top">
HTML;
            $oFCKeditor = new FCKeditor('Intro') ;//
            $oFCKeditor->BasePath = '../editor/' ;//
            $oFCKeditor->ToolbarSet = 'Default' ;//
			$oFCKeditor->Value = $rs->log_Intro;
            $oFCKeditor->Create() ;
print <<<HTML
             </tr>
          <tr>
              <td align="right" nowrap>附件:</td>
              <td colspan="2" align="left">
<iframe src="./postattach.php" scrolling="no" width="100%" height="24" frameborder="0"></iframe>              </td>
            </tr>
            <tr>
              <td colspan="3" align="center">
			  <input type="submit"value="提交日志"/>
              <input name="reset" type="button" value="取消" onClick="history.go(-1)"/>			  </td>
            </tr>
</table>
  </form>
  </div>
</div>
HTML;
		 }
		 else
		 {
		     echo "LogID Invalid.";
		 }
	 }
}
?>